package com.example.canvastouch2;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.TextView;

public class ColorSelectDialog extends Dialog {
	
	SeekBar seekRed   = null;
	SeekBar seekGreen = null;
	SeekBar seekBlue  = null;
	int colorRed      = 0;
	int colorGreen    = 0;
	int colorBlue     = 0;
	TextView textCol  = null;

	public ColorSelectDialog(Context context) {
		super(context);
	}

	public ColorSelectDialog(Context context, int theme) {
		super(context, theme);
	}

	public ColorSelectDialog(Context context, boolean cancelable,
			OnCancelListener cancelListener) {
		super(context, cancelable, cancelListener);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setTitle("�F�𒲐����Ă�������");
		this.setContentView(R.layout.content_color);
		
		seekRed   = (SeekBar)findViewById(R.id.seekRed);
		seekGreen = (SeekBar)findViewById(R.id.seekGreen);
		seekBlue  = (SeekBar)findViewById(R.id.seekBlue);
		textCol   = (TextView)findViewById(R.id.textCol);
		
		seekRed.setMax(255);
		seekGreen.setMax(255);
		seekBlue.setMax(255);
		
		SeekBarListener listener = new SeekBarListener();
		seekRed.setOnSeekBarChangeListener(listener);
		seekGreen.setOnSeekBarChangeListener(listener);
		seekBlue.setOnSeekBarChangeListener(listener);
	}
	
	class SeekBarListener implements SeekBar.OnSeekBarChangeListener {

		@Override
		public void onProgressChanged(
				SeekBar seekBar, 
				int progress,
				boolean fromUser) {
			if (fromUser) {
				int val = seekBar.getProgress();
				if (seekBar.equals(seekRed)) {
					colorRed = val;
				}
				else if (seekBar.equals(seekGreen)) {
					colorGreen = val;
				}
				else if (seekBar.equals(seekBlue)) {
					colorBlue = val;
				}
				textCol.setBackgroundColor(
						Color.rgb(
								colorRed, 
								colorGreen, 
								colorBlue));
			}
		}

		@Override
		public void onStartTrackingTouch(SeekBar seekBar) {
		}

		@Override
		public void onStopTrackingTouch(SeekBar seekBar) {
		}
		
	}
}
